import requests
# def loginfunc(a, b):
#     url = "http://ihrm-test.itheima.net/api/sys/login"
#     requestHeader = {"Content-Type": "application/json"}
#     requestBody = {"mobile": a, "password": b}
#     responed = requests.post(url=url, headers=requestHeader, json=requestBody)
#     return  responed
class TestLogin:
    def test_pass(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        requestHeader = {"Content-Type": "application/json"}
        requestBody = {"mobile": "13800000002","password": "123456"}
        responed = requests.post(url=url, headers=requestHeader, json=requestBody)
        # responed1 = loginfunc("13800000002","123456")
        # print(responed1)
        # 判断：预期结果是否等于实际结果
        assert 200 == responed.status_code
        assert True == responed.json().get('success')
        assert 10000 == responed.json().get('code')
        assert "操作成功！" == responed.json().get('message')

    def test_fail_number(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        requestHeader = {"Content-Type": "application/json"}
        requestBody = {"mobile": "138000000012342", "password": "123456"}
        responed = requests.post(url=url, headers=requestHeader, json=requestBody)
        assert 200 == responed.status_code
        assert False == responed.json().get('success')
        assert 20001 == responed.json().get('code')
        assert "用户名或密码错误" == responed.json().get('message')

    def test_fail_passwd(self):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        requestHeader = {"Content-Type": "application/json"}
        requestBody = {"mobile": "13800000002", "password": "1234561234"}
        responed = requests.post(url=url, headers=requestHeader, json=requestBody)
        assert 200 == responed.status_code
        assert False == responed.json().get('success')
        assert 20001 == responed.json().get('code')
        assert "用户名或密码错误" == responed.json().get('message')
